/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package boundary;

import entities.HodnoceniReceptu;
import entities.Recept;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Jara
 */
@Stateless
public class HodnoceniReceptuFacade extends AbstractFacade<HodnoceniReceptu> {
    @PersistenceContext(unitName = "SimpleEE6AppPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public HodnoceniReceptuFacade() {
        super(HodnoceniReceptu.class);
    }
    
    public double vratPrumernyPocetHvezdicekReceptu(Long id_recept){
        int prumer = (int)em.createQuery("SELECT AVG(hod.pocetHvezdicek) FROM HODNOCENIRECEPTU hod WHERE hod.recept_id = :id_recept") 
                .setParameter("id_recept", id_recept)
                .getSingleResult();
        return prumer;
    }
    
    public List<HodnoceniReceptu> vratVsechnaHodnoceniReceptu(Long id_recept){
        List<HodnoceniReceptu> hodnoceni = (List<HodnoceniReceptu>)em.createQuery("SELECT hod FROM HODNOCENIRECEPTU hod WHERE hod.recept_id = :id_recept") 
                .setParameter("id_recept", id_recept)
                .getResultList();
        return hodnoceni;
    }
    
}
